home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / OOmodules / list / doublylinked / stringlist.e < prev    next >
Encoding:
Text File  |  1996-04-10  |  3.7 KB  |  215 lines

  1. /*
  2.  
  3. This module contains the code of the original example program of Barry's
  4. doubly linked list module.
  5.  
  6. Gregor Goldbach September 10 1995
  7.  
  8.  
  9. Just added a new method. It takes an elist and builds a alpha sorted string
  10. list from it. The elist's entries are copied. Named the proc after queuestack's
  11. asQueuestack() asStringList().
  12.  
  13. Gregor Goldbach September 29 1995
  14.  
  15.  
  16.   April 10 1996 Gregor Goldbach
  17.     Removed the method asExecList for we have the execList object to convert
  18.     an elist. To get an execList from a stringList do this:
  19.  
  20.       /*
  21.        *  A stringList has already been built, set elist to stringList'
  22.        *  contents:
  23.        */
  24.  
  25.       elist.set(stringList.asList())
  26.  
  27.  
  28.       /*
  29.        *  Get execList from elist:
  30.        */
  31.  
  32.       NEW execList.new(["list", elist.list])
  33.  
  34.  
  35.     Renamed asStringList() to fromList().
  36.  
  37. */
  38.  
  39. OPT MODULE
  40. OPT EXPORT
  41.  
  42. MODULE 'oomodules/list/doublylinked'
  43.  
  44. OBJECT stringNode OF dlln
  45.   string
  46. ENDOBJECT
  47.  
  48. OBJECT stringList OF dllh
  49. ENDOBJECT
  50.  
  51.  
  52. PROC select(optionlist,index) OF stringNode
  53. ->  TODO: error check: len-o'-list!
  54. DEF item, value,
  55.     len
  56.  
  57.   item := ListItem(optionlist, index)
  58.  
  59.   SELECT item
  60.     CASE "set"
  61.       INC index
  62.  
  63.       self.string:=StrCopy(String(len:=StrLen(ListItem(optionlist,index))), ListItem(optionlist,index), len)
  64.  
  65.   ENDSELECT
  66.  
  67. ENDPROC index
  68.  
  69. PROC end() OF stringNode
  70.   DisposeLink(self.string)
  71. ENDPROC
  72.  
  73. PROC clear() OF stringList
  74.   DEF node:PTR TO stringNode
  75.   WHILE self.isEmpty()=FALSE
  76.     node:=self.remHead()
  77.     END node
  78.   ENDWHILE
  79. ENDPROC
  80.  
  81. PROC insertAlphaSorted(node:PTR TO stringNode) OF stringList
  82.   DEF listnode:PTR TO stringNode, done=FALSE
  83.   listnode:=self.firstNode() ->returns lastnode or tail
  84.   REPEAT
  85.     IF listnode=self.tail
  86.       done:=TRUE
  87.     ELSEIF OstrCmp(node.string, listnode.string)>=0
  88.       done:=TRUE
  89.     ELSE
  90.       listnode:=listnode.succ
  91.     ENDIF
  92.   UNTIL done
  93.   self.insert(node, listnode.pred)
  94. ENDPROC
  95.  
  96. PROC printAll() OF stringList
  97.   DEF node:PTR TO stringNode
  98.   IF self.isEmpty()
  99.     WriteF('*** List is empty\n')
  100.     RETURN
  101.   ENDIF
  102.   node:=self.firstNode()
  103.   WHILE node<>self.tail
  104.     WriteF('\s\n', node.string)
  105.     node:=node.succ
  106.   ENDWHILE
  107. ENDPROC
  108.  
  109.  
  110. PROC asList() OF stringList
  111. /*
  112.  
  113.   NAME
  114.  
  115.     asList() of stringList
  116.  
  117.   FUNCTION
  118.  
  119.     Returns an elist with the names as items.
  120.  
  121. */
  122.  
  123. DEF index,
  124.     list:PTR TO LONG,
  125.     len,
  126.     actualNode:PTR TO stringNode
  127.  
  128.   len := self.length()
  129.   IF len=0 THEN RETURN
  130.   IF (list := List(len)) = NIL THEN RETURN
  131.  
  132.  
  133.   actualNode := self.firstNode()
  134.  
  135.  
  136.   FOR index := 0 TO len-1
  137.     list[index] := actualNode.string
  138.     actualNode := actualNode.succ
  139.   ENDFOR
  140.  
  141.   SetList(list,len)
  142.  
  143.   RETURN list
  144.  
  145. ENDPROC
  146.  
  147. EXPORT PROC fromList(list) OF stringList
  148. DEF n:PTR TO stringNode,
  149.     index
  150.  
  151.   FOR index := 0 TO ListLen(list)-1
  152.  
  153.     self.insertAlphaSorted(NEW n.new(["set",ListItem(list,index)]))
  154.  
  155.   ENDFOR
  156.  
  157. ENDPROC
  158.  
  159. /*
  160.  
  161. the following method asExecList() is removed from this object because of
  162. the execList object. To get an execList from a stringList one has to do
  163. this:
  164.  
  165.   /* a stringList has already been built */
  166.  
  167.   elist.set(stringList.asList())
  168.   NEW execList.new(["list", elist.list])
  169.  
  170.  
  171.  
  172. PROC asExecList() OF stringList
  173. /*
  174.  
  175.   NAME
  176.  
  177.     asExecList() of stringList
  178.  
  179.   FUNCTION
  180.  
  181.     Returns an execlist with the names as items. Note that the
  182.     names are NOT copied.
  183.  
  184. */
  185.  
  186. DEF index,
  187.     list:PTR TO LONG,
  188.     len,
  189.     actualNode:PTR TO stringNode,
  190.  
  191.     execlist:PTR TO lh,
  192.     execnode:PTR TO ln
  193.  
  194.   execlist := newlist()
  195.  
  196.   len := self.length()
  197.   IF len=0 THEN RETURN
  198.   IF (list := List(len)) = NIL THEN RETURN
  199.  
  200.  
  201.   actualNode := self.firstNode()
  202.  
  203.  
  204.   FOR index := 0 TO len-1
  205.     execnode := newnode(NIL, actualNode.string)
  206.     AddTail(execlist,execnode)
  207.     actualNode := actualNode.succ
  208.   ENDFOR
  209.  
  210.   RETURN execlist
  211.  
  212. ENDPROC
  213.  
  214. */
  215.